<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <ui:composition template="/index.xhtml">
        <ui:define name="body">
            <h:form id="CreateClienteForm">
                <h:panelGroup id="display">
                    <p:commandButton actionListener="#{tbInstController.update}" value="#{bundle.Save}" update="display,:growl"/>
                    <p:commandButton actionListener="#{tbInstController.FecharCliente}" value="Sair" immediate="true"/>        
                    <p:confirmDialog id="CriarClienteSairDialog1" global="true" message="Cadastro alterado, deseja sair?" header="Cadastro Alterado" class="ui-confirm-dialog"  widgetVar="confirmDialog">
                        <p:commandButton value="Sim" actionListener="#{tbInstController.FecharCliente}" update=":growl" oncomplete="PF('confirmDialog').hide()" styleClass="ui-confirmdialog-yes" icon="ui-icon-check"/>
                        <p:commandButton value="Não" onclick="PF('confirmDialog').hide();" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close"/>
                    </p:confirmDialog>    
                    <br /><br />
                    <p:fieldset legend="Ajuda" style="margin-bottom:20px">
                        <h:outputText value="Bem Vindo, para completar o cadastro preencha todos os campos e clique em salvar. Os campos com * são de preenchimento obrigatório;" />
                    </p:fieldset>   
                    <p:fieldset legend="Principal" style="margin-bottom:20px">
                        <p:panelGrid columns="4" rendered="#{tbInstController.selected != null}">
                            <p:outputLabel value="#{bundle.CreateTbInstLabel_nomFantasia}" for="nomFantasia" />
                            <p:inputText id="nomFantasia" value="#{tbInstController.selected.nomFantasia}" title="#{bundle.CreateTbInstTitle_nomFantasia}" required="true" requiredMessage="#{bundle.CreateTbInstRequiredMessage_nomFantasia}" style="width: 400px;" />
                            <p:outputLabel value="#{bundle.CreateTbInstLabel_desFone1}" for="desFone1" />
                            <p:inputMask id="desFone1" value="#{tbInstController.selected.desFone1}" title="#{bundle.CreateTbInstTitle_desFone1}" required="true" requiredMessage="Campo Telefone é obrigatório" mask="(99) 9999-9999" />
                            <p:outputLabel value="#{bundle.CreateTbInstLabel_desEmail}" for="desEmail" />
                            <p:inputText id="desEmail" value="#{tbInstController.selected.desEmail}" title="#{bundle.CreateTbInstTitle_desEmail}" required="true" requiredMessage="Campo E-mail é obrigatorio" maxlength="100" style="width: 400px;" />
                            <p:outputLabel value="#{bundle.CreateTbInstLabel_desCnpjCpf}" for="desCnpjCpf" />
                            <p:inputText id="desCnpjCpf" value="#{tbInstController.selected.desCnpjCpf}" title="#{bundle.CreateTbInstTitle_desCnpjCpf}" required="true" requiredMessage="#{bundle.CreateTbInstRequiredMessage_desCnpjCpf}" />
                            <p:outputLabel value="#{bundle.CreateTbInstLabel_datNascimentoFundacao}" for="datNascimentoFundacao" />
                            <p:calendar locale="pt"  id="datNascimentoFundacao" pattern="dd/MM/yyyy" mask="99/99/9999" value="#{tbInstController.selected.datNascimentoFundacao}" title="#{bundle.EditTbInstTitle_datNascimentoFundacao}"  showOn="button"/>
                            <h:outputLabel for="menu" value="Interesses:" />
                            <p:selectCheckboxMenu id="menu" value="#{tbInstController.selectedInteresses}" label="Selecione os itens"  filter="true" filterMatchMode="startsWith" panelStyle="width:250px">
                                <f:selectItems value="#{interessesController.items}" var="interesse"  itemValue="#{interesse.id}" itemLabel="#{interesse.descricao}" />
                            </p:selectCheckboxMenu>                             
                        </p:panelGrid>                    
                    </p:fieldset>                        

                    <p:fieldset legend="Pessoa Física" style="margin-bottom:20px">
                        <p:panelGrid columns="6" rendered="#{tbInstController.selected != null}">
                            <p:outputLabel value="#{bundle.CreateTbInstLabel_desEstadocivil}" for="desEstadocivil" />
                            <p:selectOneMenu id="desEstadocivil" value="#{tbInstController.selected.desEstadocivil}">
                                <f:selectItem itemLabel="#{bundle.SelectOneMessage}"/>
                                <f:selectItem itemLabel="Solteiro" itemValue="Solteiro" />
                                <f:selectItem itemLabel="Casado" itemValue="Casado" />
                                <f:selectItem itemLabel="União Estável" itemValue="União Estável" />
                                <f:selectItem itemLabel="Divorciado" itemValue="Divorciado" />
                                <f:selectItem itemLabel="Viúvo" itemValue="Viúvo" />
                            </p:selectOneMenu>                                   
                            <p:outputLabel value="#{bundle.CreateTbInstLabel_desSexo}" for="desSexo" />
                            <p:selectOneMenu id="desSexo" value="#{tbInstController.selected.desSexo}">
                                <f:selectItem itemLabel="#{bundle.SelectOneMessage}"/>
                                <f:selectItem itemLabel="Masculino" itemValue="Masculino" />
                                <f:selectItem itemLabel="Feminino" itemValue="Feminino" />
                            </p:selectOneMenu>                                   
                            <p:outputLabel for="profissaoId" value="Profissão" />
                            <p:selectOneMenu id="profissaoId" value="#{tbInstController.selected.profissaoProfissaoId}">
                                <f:selectItem itemLabel="#{bundle.SelectOneMessage}"/>
                                <f:selectItems value="#{profissaoFormacaoController.proffisoesAvailableSelectOne}" var="profissao" itemLabel="#{profissao.descricao}" itemValue="#{profissao}" />
                            </p:selectOneMenu>                                   
                            <p:outputLabel for="formacaoId" value="Formação" />
                            <p:selectOneMenu id="formacaoId" value="#{tbInstController.selected.profissaoFormacaoId}" required="false" requiredMessage="Selecione uma formação! ">
                                <f:selectItem itemLabel="#{bundle.SelectOneMessage}"/>
                                <f:selectItems value="#{profissaoFormacaoController.formacoesAvailableSelectOne}" var="formacao" itemLabel="#{formacao.descricao}" itemValue="#{formacao}" />
                            </p:selectOneMenu>                                   
                            <p:outputLabel for="cargoId" value="Cargo" />
                            <p:selectOneMenu id="cargoId" value="#{tbInstController.selected.cargoId}" required="false" requiredMessage="Selecione uma cargo! ">
                                <f:selectItem itemLabel="#{bundle.SelectOneMessage}"/>
                                <f:selectItems value="#{cargoController.itemsAvailableSelectOne}" var="cargo" itemLabel="#{cargo.cargo}" itemValue="#{cargo}" />
                            </p:selectOneMenu>                                   
                            <p:outputLabel value="#{bundle.CreateTbInstLabel_desPassaporte}" for="desPassaporte" />
                            <p:inputText id="desPassaporte" value="#{tbInstController.selected.desPassaporte}" title="#{bundle.CreateTbInstTitle_desPassaporte}" />  
                        </p:panelGrid>                    
                    </p:fieldset>                        

                    <p:fieldset legend="Pessoa Jurídica" style="margin-bottom:20px">
                        <p:panelGrid columns="4" rendered="#{tbInstController.selected != null}">
                            <p:outputLabel value="#{bundle.CreateTbInstLabel_desRazaosocial}" for="desRazaosocial" />
                            <p:inputText id="desRazaosocial" value="#{tbInstController.selected.desRazaosocial}" title="#{bundle.CreateTbInstTitle_desRazaosocial}" style="width: 400px;" />
                            <p:outputLabel value="#{bundle.CreateTbInstLabel_desInsEstadual}" for="desInsEstadual" />
                            <p:inputText id="desInsEstadual" value="#{tbInstController.selected.desInsEstadual}" title="#{bundle.CreateTbInstTitle_desInsEstadual}" />
                            <p:outputLabel value="#{bundle.CreateTbInstLabel_desHomepage}" for="desHomepage" />
                            <p:inputText id="desHomepage" value="#{tbInstController.selected.desHomepage}" title="#{bundle.CreateTbInstTitle_desHomepage}" style="width: 400px;" />
                        </p:panelGrid>                    
                    </p:fieldset>     
                    
                    <p:fieldset legend="Categoria/subcategoria" style="margin-bottom:20px">
                        <p:panelGrid id="subcatGrid" columns="4" rendered="#{tbInstController.selected != null}">
                            <p:outputLabel for="categoriaId" value="Categoria" />
                            <p:selectOneMenu id="categoriaId" value="#{tbInstController.cat}">
                                <f:selectItem itemLabel="#{bundle.SelectOneMessage}" value="#{null}" />
                                <f:selectItems value="#{categoriaController.itemsAvailableSelectOne}" var="cat" itemLabel="#{cat.descricao}" itemValue="#{cat}" />
                                <p:ajax update="subcategoriaId subcatGrid" />
                            </p:selectOneMenu>   
                            <p:outputLabel for="subcategoriaId" value="Subcategoria" /> 
                            <p:selectOneMenu id="subcategoriaId" value="#{tbInstController.selected.subcategoriaId}" rendered="#{tbInstController.cat != null}">
                                <f:selectItems value="#{subcategoriaController.getSubcatByCatSelectOne(tbInstController.cat)}" var="subcat" itemLabel="#{subcat.descricao}" itemValue="#{subcat}" rendered="#{subcat.categoriaId.id == tbInstController.selected.subcategoriaId.categoriaId.id}"/>
                            </p:selectOneMenu>   
                            <p:selectOneMenu id="emptySubcat" rendered="#{tbInstController.cat == null}" disabled="true">
                                <f:selectItem itemLabel="Selecione uma categoria"/>
                            </p:selectOneMenu>                                  
                        </p:panelGrid>  
                    </p:fieldset>   
                    
                    <p:fieldset legend="Dados Cadastrais" style="margin-bottom:20px">
                        <p:panelGrid columns="4" rendered="#{tbInstController.selected != null}">
                            <p:outputLabel value="#{bundle.CreateTbInstLabel_desEndereco}" for="desEndereco" />
                            <p:inputText id="desEndereco" value="#{tbInstController.selected.desEndereco}" title="#{bundle.CreateTbInstTitle_desEndereco}" style="width: 400px;" />
                            <p:outputLabel value="#{bundle.CreateTbInstLabel_desBairro}" for="desBairro" />
                            <p:inputText id="desBairro" value="#{tbInstController.selected.desBairro}" title="#{bundle.CreateTbInstTitle_desBairro}" style="width: 400px;" />
                            <p:outputLabel value="#{bundle.CreateTbInstLabel_desCxpostal}" for="desCxpostal" />
                            <p:inputText id="desCxpostal" value="#{tbInstController.selected.desCxpostal}" title="#{bundle.CreateTbInstTitle_desCxpostal}" />
                            <p:outputLabel value="#{bundle.CreateTbInstLabel_desCep}" for="desCep" />
                            <p:inputMask id="desCep" value="#{tbInstController.selected.desCep}" title="#{bundle.CreateTbInstTitle_desCep}" mask="99999-999"/>
                            <p:outputLabel value="#{bundle.CreateTbInstLabel_desCidade}" for="desCidade" />
                            <p:inputText id="desCidade" value="#{tbInstController.selected.desCidade}" title="#{bundle.CreateTbInstTitle_desCidade}" />
                            <p:outputLabel value="#{bundle.CreateTbInstLabel_desUf}" for="desUf" />
                            <p:selectOneMenu id="desUf" value="#{tbInstController.selected.desUf}">
                                <f:selectItem itemLabel="#{bundle.SelectOneMessage}"/>
                                <f:selectItem itemLabel="AC" itemValue="AC" />
                                <f:selectItem itemLabel="AL" itemValue="AL" />
                                <f:selectItem itemLabel="AP" itemValue="AP" />
                                <f:selectItem itemLabel="AM" itemValue="AM" />
                                <f:selectItem itemLabel="BA" itemValue="BA" />
                                <f:selectItem itemLabel="CE" itemValue="CE" />
                                <f:selectItem itemLabel="DF" itemValue="DF" />
                                <f:selectItem itemLabel="ES" itemValue="ES" />
                                <f:selectItem itemLabel="GO" itemValue="GO" />
                                <f:selectItem itemLabel="MA" itemValue="MA" />
                                <f:selectItem itemLabel="MT" itemValue="MT" />
                                <f:selectItem itemLabel="MS" itemValue="MS" />
                                <f:selectItem itemLabel="MG" itemValue="MG" />
                                <f:selectItem itemLabel="PR" itemValue="PR" />
                                <f:selectItem itemLabel="PB" itemValue="PB" />
                                <f:selectItem itemLabel="PA" itemValue="PA" />
                                <f:selectItem itemLabel="PE" itemValue="PE" />
                                <f:selectItem itemLabel="PI" itemValue="PI" />
                                <f:selectItem itemLabel="RJ" itemValue="RJ" />
                                <f:selectItem itemLabel="RN" itemValue="RN" />
                                <f:selectItem itemLabel="RS" itemValue="RS" />
                                <f:selectItem itemLabel="RO" itemValue="RO" />
                                <f:selectItem itemLabel="RR" itemValue="RR" />
                                <f:selectItem itemLabel="SC" itemValue="SC" />
                                <f:selectItem itemLabel="SE" itemValue="SE" />
                                <f:selectItem itemLabel="SP" itemValue="SP" />
                                <f:selectItem itemLabel="TO" itemValue="TO" />      
                            </p:selectOneMenu>                                   
                            <p:outputLabel value="#{bundle.CreateTbInstLabel_desPais}" for="desPais" />
                            <p:inputText id="desPais" value="#{tbInstController.selected.desPais}" title="#{bundle.CreateTbInstTitle_desPais}" />
                            <p:outputLabel value="#{bundle.CreateTbInstLabel_desFone2}" for="desFone2" />
                            <p:inputMask id="desFone2" value="#{tbInstController.selected.desFone2}" title="#{bundle.CreateTbInstTitle_desFone2}" mask="(99) 9999-9999"/>
                            <p:outputLabel value="E-mail 2" for="desFone3" />
                            <p:inputText id="desFone3" value="#{tbInstController.selected.desFone3}" maxlength="100" title="E-mail 2"/>
                            <p:outputLabel value="#{bundle.CreateTbInstLabel_desFax}" for="desFax" />
                            <p:inputMask id="desFax" value="#{tbInstController.selected.desFax}" title="#{bundle.CreateTbInstTitle_desFax}" mask="(99) 9999-9999"/>
                            <p:outputLabel value="Receber Informações" for="desNewsletter" />
                            <p:selectOneMenu id="desNewsletter" value="#{tbInstController.selected.desNewsletter}" required="false">
                                <f:selectItem itemLabel="Não" itemValue="N" />
                                <f:selectItem itemLabel="Sim" itemValue="S" />
                            </p:selectOneMenu>   
                            <p:outputLabel value="#{bundle.CreateTbInstLabel_desObsInst}" for="desObsInst" />
                            <p:inputTextarea rows="4" cols="60" id="desObsInst" value="#{tbInstController.selected.desObsInst}" title="#{bundle.CreateTbInstTitle_desObsInst}" />
                        </p:panelGrid>                    
                    </p:fieldset>     
                    <input type="password" name="password_fake" id="password_fake" value="" style="display: none;" />
                    <p:fieldset legend="Acesso Senha" style="margin-bottom:20px">
                        <p:panelGrid columns="2" rendered="#{tbInstController.selected != null}">
                            <p:outputLabel value="#{bundle.CreateTbInstLabel_desSenha}" for="desSenha" />
                            <p:password id="desSenha" value="#{tbInstController.selected.desSenha}" redisplay="false" title="#{bundle.CreateTbInstTitle_desSenha}" autocomplete="off"  />
                        </p:panelGrid>                    
                    </p:fieldset>                        
                    <p:commandButton actionListener="#{tbInstController.update}" value="#{bundle.Save}" oncomplete="if (args &amp;&amp; !args.validationFailed) PF('confirmDialog').show()" update=":growl"/>
                    <p:commandButton actionListener="#{tbInstController.FecharCliente}" value="Sair" immediate="true"/>        
                    <p:confirmDialog id="CriarClienteSairDialog" global="true" message="Cadastro alterado, deseja sair?" header="Cadastro Alterado" class="ui-confirm-dialog"  widgetVar="confirmDialog">
                        <p:commandButton value="Sim" actionListener="#{tbInstController.FecharCliente}" update=":growl" oncomplete="PF('confirmDialog').hide()" styleClass="ui-confirmdialog-yes" icon="ui-icon-check"/>
                        <p:commandButton value="Não" onclick="PF('confirmDialog').hide();" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close"/>
                    </p:confirmDialog>    
                </h:panelGroup>                 
            </h:form>
        </ui:define>
    </ui:composition>
</html>
